package cn.itsource.crm.web.controller;

import cn.itsource.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@CrossOrigin//解决跨域问题
@RequestMapping("/account")
public class MailController {

    @Autowired
    private JavaMailSender mailSender;
    @RequestMapping("/mail")
    @ResponseBody
    public AjaxResult sendEmail(String toEmail){

        try {
            //创建发送普通邮件对象
            SimpleMailMessage message = new SimpleMailMessage();
            //邮件来源于哪个邮箱
            message.setFrom("1904520939@qq.com");
            //邮件标题
            message.setSubject("维修保养取车通知！！！");
            //邮件内容
            message.setText("您的爱车已经维修保养完成，您可以过来取走您的爱车了！！！");
            //发送到目的地邮箱
            message.setTo("729361504@qq.com");
            mailSender.send(message);
            return new AjaxResult(true,"发送成功！");
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult("发送失败！请重试！");
        }
    }
}
